package com.alog.javaee.day41;

import org.springframework.util.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @Auther: Ye Zhengdong
 * @Date: 2019/2/23 21:39
 * @Description:
 */
@WebServlet("/day41/findUserByPage")
public class FindUserByPage extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String currentPage = req.getParameter("currentPage");
        if(StringUtils.isEmpty(currentPage)){
            currentPage = "1";
        }

        Map<String, String[]> parameterMap = req.getParameterMap();

        UserService service = new UserServiceImpl();
        PageBean<User> pb = service.findUserByPage(currentPage, parameterMap);
        req.setAttribute("pb", pb);
        req.getRequestDispatcher("/day41/list.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
